#include "gpu_utility.h"
#include <DXGI.h>
#include <vector>
#include <stdio.h>
#include <string.h>


std::string WStringToString(const std::wstring& wstr)
{
	std::string str(wstr.length(), ' ');
	std::copy(wstr.begin(), wstr.end(), str.begin());
	return str;
}

std::string GetGPUModel()
{
	// Create factory
	IDXGIFactory* pFactory;
	IDXGIAdapter* pAdapter;
	std::vector <IDXGIAdapter*>  vAdapters; // Adapters

	int iAdapterNum = 0; // Adapter count

	// Create DXGI factory
	HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory));

	if (FAILED(hr))
		return "";

	// Enumerate adapters
	while (pFactory->EnumAdapters(iAdapterNum, &pAdapter) != DXGI_ERROR_NOT_FOUND)
	{
		vAdapters.push_back(pAdapter);
		++iAdapterNum;
	}

	// Check info
	for (size_t i = 0; i < vAdapters.size(); i++)
	{
		// Get info
		DXGI_ADAPTER_DESC adapterDesc;
		vAdapters[i]->GetDesc(&adapterDesc);
		std::wstring wad(adapterDesc.Description);
		std::string wa = WStringToString(wad);
		return wa;
	}
	vAdapters.clear();

	return "";
}
